package gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;

import javax.media.j3d.Canvas3D;
import javax.swing.JFrame;
import javax.swing.UIManager;

import main.LabyrinthControl;

import com.sun.j3d.utils.universe.SimpleUniverse;

/**
 * The main window in Swing
 * 
 * @author Johannes Kulick
 * @version 0.1
 * @licence GNU Lesser General Public License
 */
public class MainWindow extends JFrame {
	private static final long serialVersionUID = -2414472446751157037L;
	private Canvas3D mLabArea;
	private ControlPanel mControlPanel;
	/**
	 * Returns the Canvas3D Object of the main window
	 * @return the Canvas§D Object
	 */
	public Canvas3D getLabArea() {
		return mLabArea;
	}
	/**
	 * Constructor
	 * @param title Window title
	 * @param control The central LabyrinthControl
	 */
	public MainWindow(String title, LabyrinthControl control) {
		// Set window title
		super(title);

		setFocusable(true);
		
		// Set the native Look & Feel for swing and ignore errors here...
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		} 
		
		// resize start window
		setPreferredSize(new Dimension(1024, 768));
		
		// Close on click on X and so on
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		// Use a layoutmanager for the main window
		setLayout(new BorderLayout());
		
		
		// TODO: Create control elements here...

		// Create the area for the labyrinth
		// 1. Configuration...
		GraphicsConfiguration config = SimpleUniverse
				.getPreferredConfiguration();
		// 2. Create picturearea
		mLabArea = new Canvas3D(config);
		
		mControlPanel = new ControlPanel(control);
		add(mControlPanel, BorderLayout.LINE_START);
		add(mLabArea, BorderLayout.CENTER);
	}
	public void updateAgentList() {
		mControlPanel.updateAgentList();
	}

}
